import httpRequest from '@/config/axios/httpRequest'
import {
  ApostilleTaskReq,
  ApproveTaskReq,
  ApproveTaskResp,
  CopyTaskReq,
  CopyTaskResp,
  DelegateTaskReq,
  DelegateTaskResp,
  GetChildrenTaskListReq,
  GetChildrenTaskListResp,
  GetTaskDonePageReq,
  GetTaskDonePageResp,
  GetTaskListByProcessInstanceIdReq,
  GetTaskListByProcessInstanceIdResp,
  GetTaskManagerPageReq,
  GetTaskManagerPageResp,
  GetTaskMyTodoPageReq,
  GetTaskMyTodoPageResp,
  GetTaskReturnPageResp,
  GetTaskTodoPageReq,
  GetTaskTodoPageResp,
  RejectTaskReq,
  RejectTaskResp,
  ReturnTaskReq,
  ReturnTaskResp,
  TransferTaskReq
} from '@/models/bpm/BpmTaskModel'
import bpmapi from '../bpmapi'
import { DeleteDeptResp } from '@/models/base/DepartmentModel'

export const getTaskTodoPage = async (params: GetTaskTodoPageReq) => {
  return await httpRequest.get<GetTaskTodoPageResp>(bpmapi.BpmTaskTodoPage, { params })
}

export const getTaskDonePage = async (params: GetTaskDonePageReq) => {
  return await httpRequest.get<GetTaskDonePageResp>(bpmapi.BpmTaskDonePage, { params })
}

export const getTaskManagerPage = async (params: GetTaskManagerPageReq) => {
  return await httpRequest.get<GetTaskManagerPageResp>(bpmapi.BpmTaskManagerPage, { params })
}

export const approveTask = async (data: ApproveTaskReq) => {
  return await httpRequest.put<ApproveTaskResp>(bpmapi.BpmTaskApprove, data)
}

export const rejectTask = async (data: RejectTaskReq) => {
  return await httpRequest.put<RejectTaskResp>(bpmapi.BpmTaskReject, data)
}

export const getTaskListByProcessInstanceId = async (params: GetTaskListByProcessInstanceIdReq) => {
  return await httpRequest.get<GetTaskListByProcessInstanceIdResp>(
    bpmapi.BpmTaskListByProcessInstanceId,
    { params }
  )
}

// 获取所有可退回的节点
export const getTaskListByReturn = async (id: string) => {
  return await httpRequest.get<GetTaskReturnPageResp>(bpmapi.BpmTaskGetTaskReturnPage, {
    params: { Id: id }
  })
}

// 退回
export const returnTask = async (data: ReturnTaskReq) => {
  return await httpRequest.put<ReturnTaskResp>(bpmapi.BpmTaskReturn, data)
}

// 委派
export const delegateTask = async (data: DelegateTaskReq) => {
  return await httpRequest.put<DeleteDeptResp>(bpmapi.BpmTaskDelegate, data)
}

// 转派
export const transferTask = async (data: any) => {
  return await httpRequest.put<TransferTaskReq>(bpmapi.BpmTaskTransfer, data)
}

// 加签
export const signCreateTask = async (data: ApostilleTaskReq) => {
  return await httpRequest.put<ApostilleTaskReq>(bpmapi.BpmTaskAdd, data)
}

// 减签
export const signDeleteTask = async (data: DelegateTaskReq) => {
  return await httpRequest.delete<DelegateTaskResp>(bpmapi.BpmTaskDelete, { data })
}

// 抄送
export const copyTask = async (data: CopyTaskReq) => {
  return await httpRequest.put<CopyTaskResp>(bpmapi.BpmTaskCopy, data)
}

// 获取我的待办任务
export const myTodoTask = async (data: GetTaskMyTodoPageReq) => {
  return await httpRequest.get<GetTaskMyTodoPageResp>(bpmapi.BpmTaskMyTodoPage, { data })
}

// 获取减签任务列表
export const getChildrenTaskList = async (params: GetChildrenTaskListReq) => {
  return await httpRequest.get<GetChildrenTaskListResp>(bpmapi.BpmTaskGetChildrenTaskList, {
    params
  })
}
